#include "bms_Slave.h"
#include "rtwtypes.h"
#include "bms_Slave_Diagnose_system.h"
#include "Alarm_nonRecov_sys.h"
#include "Alarm_Recov_sys.h"
#include <math.h>
#include "rt_nonfinite.h"
#include "ABI.h"
#include "calPrms.h"
#include "ASW_Signal.h"

void bms_Slave_Diagnose_system_Init(void)
{
  boolean_T rtb_Alarm_flg_a;
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_a3);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_p);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_n1);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_oe);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_c5);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_df);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_br);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_ll);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_dc);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_nq);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_li);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_hj);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_aa);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_n);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_gx);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_d);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_jz);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_c3);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_dr);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_jq);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_ja);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_p0);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_nt);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_c0);
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_as);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_k);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_g);
  bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_c);
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  Alarm_nonRecov_sys_Init(&rtb_Alarm_flg_a);
  bms_Slave_Alarm_Recov_sys_Init(&rtb_Alarm_flg_a);
}

void bms_Slave_Diagnose_system_Reset(boolean_T *rtb_Alarm_flg_dc1, boolean_T
  *rtb_Alarm_flg_dc13mdvk)
{
  int32_T i;
  boolean_T rtb_Alarm_flg_p;
  bms_Slave_DW.UnitDelay_DSTATE_l = 0.0F;
  bms_Slave_DW.UnitDelay1_DSTATE_f = 0U;
  bms_Slave_DW.UnitDelay2_DSTATE_h = 0U;
  Alarm_nonRecov_sys_Reset(rtb_Alarm_flg_dc1,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys4);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_a3,
    &bms_Slave_DW.sf_Alarm_Recov_sys7);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_Recov_sys5);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_n1,
    &bms_Slave_DW.sf_Alarm_Recov_sys14);
  for (i = 0; i < 10; i++) {
    bms_Slave_DW.FlsTperChip[i] = 0U;
  }

  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_oe,
    &bms_Slave_DW.sf_Alarm_Recov_sys15);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_c5,
    &bms_Slave_DW.sf_Alarm_Recov_sys16);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_df,
    &bms_Slave_DW.sf_Alarm_Recov_sys17);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_br,
    &bms_Slave_DW.sf_Alarm_Recov_sys8);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_ll,
    &bms_Slave_DW.sf_Alarm_Recov_sys11_k);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_dc,
    &bms_Slave_DW.sf_Alarm_Recov_sys3_j);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_nq,
    &bms_Slave_DW.sf_Alarm_Recov_sys2_b);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_li,
    &bms_Slave_DW.sf_Alarm_Recov_sys4);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_hj,
    &bms_Slave_DW.sf_Alarm_Recov_sys3_l);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_aa,
    &bms_Slave_DW.sf_Alarm_Recov_sys1_g);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_n,
    &bms_Slave_DW.sf_Alarm_Recov_sys2_f);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_gx,
    &bms_Slave_DW.sf_Alarm_Recov_sys5_l);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_d,
    &bms_Slave_DW.sf_Alarm_Recov_sys9);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_jz,
    &bms_Slave_DW.sf_Alarm_Recov_sys4_i);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_c3,
    &bms_Slave_DW.sf_Alarm_Recov_sys);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_dr,
    &bms_Slave_DW.sf_Alarm_Recov_sys1_j);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_jq,
    &bms_Slave_DW.sf_Alarm_Recov_sys19);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_ja,
    &bms_Slave_DW.sf_Alarm_Recov_sys10_i);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_p0,
    &bms_Slave_DW.sf_Alarm_Recov_sys12);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_nt,
    &bms_Slave_DW.sf_Alarm_Recov_sys13);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_c0,
    &bms_Slave_DW.sf_Alarm_Recov_sys18);
  Alarm_nonRecov_sys_Reset(rtb_Alarm_flg_dc13mdvk,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_as,
    &bms_Slave_DW.sf_Alarm_Recov_sys6);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_k,
    &bms_Slave_DW.sf_Alarm_Recov_sys9_m);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_g,
    &bms_Slave_DW.sf_Alarm_Recov_sys8_p);
  bms_Slave_Alarm_Recov_sys_Reset(&bms_Slave_B.Alarm_flg_c,
    &bms_Slave_DW.sf_Alarm_Recov_sys7_d);
  Alarm_nonRecov_sys_Reset(&rtb_Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys3);
  Alarm_nonRecov_sys_Reset(&rtb_Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys5);
  Alarm_nonRecov_sys_Reset(&rtb_Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys_n);
  Alarm_nonRecov_sys_Reset(&rtb_Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys1);
  Alarm_nonRecov_sys_Reset(&rtb_Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys2);
  Alarm_nonRecov_sys_Reset(&rtb_Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys6);
  Alarm_nonRecov_sys_Reset(&rtb_Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_nonRecov_sys7);
  bms_Slave_Alarm_Recov_sys_Reset(&rtb_Alarm_flg_p,
    &bms_Slave_DW.sf_Alarm_Recov_sys3_b);
}

void bms_Sla_Diagnose_system_Disable(void)
{
  bms_Slave_DW.Diagnose_system_MODE = false;
}

void bms_Slave_Diagnose_system(void)
{
  int32_T j;
  uint8_T tmpForInput[80];
  boolean_T rtb_VectorConcatenate[8];
  boolean_T rtb_VectorConcatenate1[8];
  boolean_T rtb_Alarm_flg_k;
  boolean_T rtb_Alarm_flg_n;
  boolean_T rtb_RelationalOperator6_pt;
  if (bms_Slave_B.LogicalOperator3) {
    int32_T bitIdx;
    real32_T rtb_Add8;
    uint32_T bitMask;
    uint32_T rtb_Product;
    uint16_T rtb_Constant3;
    uint8_T rtb_CellTDiff_OverAlert;
    uint8_T rtb_CellT_LowAlert;
    uint8_T rtb_CellT_OverAlert1;
    uint8_T rtb_CellT_OverAlert2;
    uint8_T rtb_CellT_OverAlert3;
    uint8_T rtb_CellVDiff_OverAlert1;
    uint8_T rtb_CellVDiff_OverAlert2;
    uint8_T rtb_CellV_LowAlert3;
    uint8_T rtb_CellV_OverAlert1;
    uint8_T rtb_CellV_OverAlert2;
    uint8_T rtb_CellV_OverAlert3;
    uint8_T rtb_Switch11;
    uint8_T rtb_Switch12_h;
    uint8_T rtb_Switch13;
    uint8_T rtb_Switch15;
    uint8_T rtb_Switch20_p;
    uint8_T rtb_Switch21;
    uint8_T rtb_Switch23;
    uint8_T rtb_Switch25;
    uint8_T rtb_Switch27;
    uint8_T rtb_Switch2_d;
    uint8_T rtb_Switch2_p;
    uint8_T rtb_Switch34;
    uint8_T rtb_Switch5;
    uint8_T rtb_Switch7;
    uint8_T rtb_Switch9;
    if (!bms_Slave_DW.Diagnose_system_MODE) {
      bms_Slave_Diagnose_system_Reset(&rtb_Alarm_flg_n, &rtb_Alarm_flg_k);
      bms_Slave_DW.Diagnose_system_MODE = true;
    }

    rtb_RelationalOperator6_pt = (bms_Slave_B.Open_The_Barn_door_c == 1);
    Alarm_nonRecov_sys(false, Other_LowSOC_Almtime, &rtb_Alarm_flg_n,
                       &bms_Slave_DW.sf_Alarm_nonRecov_sys4);
    if (rtb_Alarm_flg_n) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellT_OverAlert1 = 0U;
      } else {
        rtb_CellT_OverAlert1 = 7U;
      }
    } else {
      rtb_CellT_OverAlert1 = 0U;
    }

    rtb_VectorConcatenate[0] = (rtb_CellT_OverAlert1 != 0);
    rtb_Constant3 = (uint16_T)(bms_Slave_B.CellV_max - bms_Slave_B.CellV_min);
    bms_Slave_Alarm_Recov_sys(((bms_Slave_DW.UnitDelay8_DSTATE > 10.0F) &&
      (rtb_Constant3 >= CellV_Diff_LV1)) || ((bms_Slave_DW.UnitDelay8_DSTATE <=
      10.0F) && (rtb_Constant3 >= CellV_Diff_LV1_Below10)),
      ((bms_Slave_DW.UnitDelay8_DSTATE > 10.0F) && (rtb_Constant3 <
      CellV_DiffRec_LV1)) || ((bms_Slave_DW.UnitDelay8_DSTATE <= 10.0F) &&
      (rtb_Constant3 < CellV_DiffRec_LV1_Below10)), Cell_OverDiffV1_Almtime,
      Cell_OverDiffV1_Rcvtime, &bms_Slave_B.Alarm_flg_a3,
      &bms_Slave_DW.sf_Alarm_Recov_sys7);
    if (bms_Slave_B.Alarm_flg_a3) {
      rtb_CellVDiff_OverAlert1 = 1U;
    } else {
      rtb_CellVDiff_OverAlert1 = 0U;
    }

    bms_Slave_Alarm_Recov_sys(((bms_Slave_DW.UnitDelay8_DSTATE > 10.0F) &&
      (rtb_Constant3 >= CellV_Diff_LV2)) || ((bms_Slave_DW.UnitDelay8_DSTATE <=
      10.0F) && (rtb_Constant3 >= CellV_Diff_LV2_Below10)),
      ((bms_Slave_DW.UnitDelay8_DSTATE > 10.0F) && (rtb_Constant3 <
      CellV_DiffRec_LV2)) || ((bms_Slave_DW.UnitDelay8_DSTATE <= 10.0F) &&
      (rtb_Constant3 < CellV_DiffRec_LV2_Below10)), Cell_OverDiffV2_Almtime,
      Cell_OverDiffV2_Rcvtime, &bms_Slave_B.Alarm_flg_p,
      &bms_Slave_DW.sf_Alarm_Recov_sys5);
    if (bms_Slave_B.Alarm_flg_p) {
      rtb_CellVDiff_OverAlert2 = 5U;
    } else {
      rtb_CellVDiff_OverAlert2 = 0U;
    }

    rtb_Alarm_flg_n = (bms_Slave_B.LogicalOperator20 && ((bms_Slave_B.CellV_max >
      CellV_Sensor_High_Coff) || (bms_Slave_B.CellV_min < CellV_Sensor_Low_Coff)));
    bms_Slave_Alarm_Recov_sys(rtb_Alarm_flg_n, !rtb_Alarm_flg_n,
      Cell_SensorV_Almtime, Cell_SensorV_Rcvtime, &bms_Slave_B.Alarm_flg_n1,
      &bms_Slave_DW.sf_Alarm_Recov_sys14);
    if (bms_Slave_B.Alarm_flg_n1) {
      rtb_Switch25 = 1U;
    } else {
      rtb_Switch25 = 0U;
    }

    rtb_VectorConcatenate[1] = ((rtb_CellVDiff_OverAlert1 != 0) ||
      (rtb_CellVDiff_OverAlert2 != 0) || (rtb_Switch25 != 0));
    rtb_VectorConcatenate[2] = bms_Slave_ConstB.Compare;
    rtb_VectorConcatenate[3] = bms_Slave_ConstB.Compare_i;
    bms_Slave_Alarm_Recov_sys(false, true, Cell_SensorT1_Almtime,
      Cell_SensorT1_Rcvtime, &bms_Slave_B.Alarm_flg_oe,
      &bms_Slave_DW.sf_Alarm_Recov_sys15);
    if (bms_Slave_B.Alarm_flg_oe) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch27 = 6U;
      } else {
        rtb_Switch27 = 5U;
      }
    } else {
      rtb_Switch27 = 0U;
    }

    bms_Slave_Alarm_Recov_sys(false, true, Cell_SensorT2_Almtime,
      Cell_SensorT2_Rcvtime, &bms_Slave_B.Alarm_flg_c5,
      &bms_Slave_DW.sf_Alarm_Recov_sys16);
    bms_Slave_Alarm_Recov_sys(bms_Slave_B.LogicalOperator1,
      !bms_Slave_B.LogicalOperator1, Cell_StrayT_Almtime, Cell_StrayT_Rcvtime,
      &bms_Slave_B.Alarm_flg_df, &bms_Slave_DW.sf_Alarm_Recov_sys17);
    if (bms_Slave_B.Alarm_flg_c5) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellT_OverAlert1 = 6U;
      } else {
        rtb_CellT_OverAlert1 = 5U;
      }
    } else {
      rtb_CellT_OverAlert1 = 0U;
    }

    if (bms_Slave_B.Alarm_flg_df) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellT_LowAlert = 6U;
      } else {
        rtb_CellT_LowAlert = 5U;
      }
    } else {
      rtb_CellT_LowAlert = 0U;
    }

    rtb_VectorConcatenate[4] = ((rtb_Switch27 != 0) || (rtb_CellT_OverAlert1 !=
      0) || (rtb_CellT_LowAlert != 0));
    bms_Slave_Alarm_Recov_sys(bms_Slave_B.CellT_max >= CellT_Over_LV1,
      bms_Slave_B.CellT_max < CellT_OverRec_LV1, Cell_OverT1_Almtime,
      Cell_OverT1_Rcvtime, &bms_Slave_B.Alarm_flg_br,
      &bms_Slave_DW.sf_Alarm_Recov_sys8);
    if (bms_Slave_B.Alarm_flg_br) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellT_OverAlert1 = 5U;
      } else {
        rtb_CellT_OverAlert1 = 1U;
      }
    } else {
      rtb_CellT_OverAlert1 = 0U;
    }

    rtb_VectorConcatenate[5] = (rtb_CellT_OverAlert1 != 0);
    rtb_VectorConcatenate[6] = false;
    bms_Slave_Alarm_Recov_sys(bms_Slave_B.CellT_min < CellT_Low_LV1,
      bms_Slave_B.CellT_min > CellT_LowRec_LV1, Cell_UnderT_Almtime,
      Cell_UnderT_Rcvtime, &bms_Slave_B.Alarm_flg_ll,
      &bms_Slave_DW.sf_Alarm_Recov_sys11_k);
    if (bms_Slave_B.Alarm_flg_ll) {
      rtb_CellT_LowAlert = 1U;
    } else {
      rtb_CellT_LowAlert = 0U;
    }

    rtb_VectorConcatenate[7] = (rtb_CellT_LowAlert != 0);
    bitIdx = 0;
    rtb_Product = 0U;
    bitMask = 1U;
    for (j = 0; j < 8; j++) {
      if (rtb_VectorConcatenate[bitIdx]) {
        rtb_Product |= bitMask;
      }

      bitIdx++;
      bitMask <<= 1U;
    }

    bms_Slave_B.CMC_Alarm_1 = (uint8_T)rtb_Product;
    rtb_Alarm_flg_k = (bms_Slave_B.LogicalOperator20 &&
                       (bms_Slave_B.AFE_Signal.INI_Finish_flg == 0) &&
                       bms_Slave_B.LogicalOperator20 &&
                       (bms_Slave_B.AFE_Signal.INI_Finish_flg == 0));
    bms_Slave_Alarm_Recov_sys(rtb_Alarm_flg_k && (bms_Slave_B.CellV_max >=
      CellV_Over_LV1), bms_Slave_B.CellV_max < CellV_OverRec_LV1,
      Cell_OverV1_Almtime, Cell_OverV1_Rcvtime, &bms_Slave_B.Alarm_flg_dc,
      &bms_Slave_DW.sf_Alarm_Recov_sys3_j);
    if (bms_Slave_B.Alarm_flg_dc) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellV_OverAlert1 = 7U;
      } else {
        rtb_CellV_OverAlert1 = 1U;
      }
    } else {
      rtb_CellV_OverAlert1 = 0U;
    }

    bms_Slave_Alarm_Recov_sys(rtb_Alarm_flg_k && (bms_Slave_B.CellV_max >=
      CellV_Over_LV2), bms_Slave_B.CellV_max < CellV_OverRec_LV2,
      Cell_OverV2_Almtime, Cell_OverV2_Rcvtime, &bms_Slave_B.Alarm_flg_nq,
      &bms_Slave_DW.sf_Alarm_Recov_sys2_b);
    if (bms_Slave_B.Alarm_flg_nq) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellV_OverAlert2 = 8U;
      } else {
        rtb_CellV_OverAlert2 = 1U;
      }
    } else {
      rtb_CellV_OverAlert2 = 0U;
    }

    bms_Slave_Alarm_Recov_sys(rtb_Alarm_flg_k && (bms_Slave_B.CellV_max >=
      CellV_Over_LV3), bms_Slave_B.CellV_max < CellV_OverRec_LV3,
      Cell_OverV3_Almtime, Cell_OverV3_Rcvtime, &bms_Slave_B.Alarm_flg_li,
      &bms_Slave_DW.sf_Alarm_Recov_sys4);
    if (bms_Slave_B.Alarm_flg_li) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellV_OverAlert3 = 8U;
      } else {
        rtb_CellV_OverAlert3 = 1U;
      }
    } else {
      rtb_CellV_OverAlert3 = 0U;
    }

    rtb_VectorConcatenate1[0] = ((rtb_CellV_OverAlert1 != 0) ||
      (rtb_CellV_OverAlert2 != 0) || (rtb_CellV_OverAlert3 != 0));
    rtb_Add8 = -1000.0F * bms_Slave_DW.UnitDelay24_DSTATE;
    bms_Slave_Alarm_Recov_sys(((rtb_Add8 < -10000.0F) && (bms_Slave_B.Current <=
      rtb_Add8 * 1.1F - 1000.0F) && rtb_RelationalOperator6_pt) || ((rtb_Add8 >=
      -10000.0F) && (bms_Slave_B.Current <= rtb_Add8 - 2000.0F) &&
      rtb_RelationalOperator6_pt), bms_Slave_B.Current >= (real32_T)
      bms_Slave_B.Current * 0.95F, OverCur_Chrg1_Almtime, OverCur_Chrg1_Rcvtime,
      &bms_Slave_B.Alarm_flg_hj, &bms_Slave_DW.sf_Alarm_Recov_sys3_l);
    if (bms_Slave_B.Alarm_flg_hj) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch20_p = 5U;
      } else {
        rtb_Switch20_p = 0U;
      }
    } else {
      rtb_Switch20_p = 0U;
    }

    bms_Slave_Alarm_Recov_sys(((rtb_Add8 < -10000.0F) && (bms_Slave_B.Current <=
      rtb_Add8 * 1.2F - 1000.0F) && rtb_RelationalOperator6_pt) || ((rtb_Add8 >=
      -10000.0F) && (bms_Slave_B.Current <= rtb_Add8 - 3000.0F) &&
      rtb_RelationalOperator6_pt), bms_Slave_B.Current >= 0.0F,
      OverCur_Chrg2_Almtime, OverCur_Chrg2_Rcvtime, &bms_Slave_B.Alarm_flg_aa,
      &bms_Slave_DW.sf_Alarm_Recov_sys1_g);
    if (bms_Slave_B.Alarm_flg_aa) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch2_p = 6U;
      } else {
        rtb_Switch2_p = 0U;
      }
    } else {
      rtb_Switch2_p = 0U;
    }

    bms_Slave_Alarm_Recov_sys(((rtb_Add8 < -10000.0F) && (bms_Slave_B.Current <=
      rtb_Add8 * 1.3F - 1000.0F) && rtb_RelationalOperator6_pt) || ((rtb_Add8 >=
      -10000.0F) && (bms_Slave_B.Current <= rtb_Add8 - 4000.0F) &&
      rtb_RelationalOperator6_pt), bms_Slave_B.Current >= 0,
      OverCur_Chrg3_Almtime, OverCur_Chrg3_Rcvtime, &bms_Slave_B.Alarm_flg_n,
      &bms_Slave_DW.sf_Alarm_Recov_sys2_f);
    if (bms_Slave_B.Alarm_flg_n) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch12_h = 7U;
      } else {
        rtb_Switch12_h = 0U;
      }
    } else {
      rtb_Switch12_h = 0U;
    }

    rtb_VectorConcatenate1[1] = ((rtb_Switch20_p != 0) || (rtb_Switch2_p != 0) ||
      (rtb_Switch12_h != 0));
    rtb_VectorConcatenate1[2] = (rtb_CellT_LowAlert != 0);
    rtb_Alarm_flg_n = ((bms_Slave_B.AFE_Signal.DischrgMOS_State != 0) &&
                       (bms_Slave_B.AFE_Signal.ChrgMOS_State != 0));
    bms_Slave_Alarm_Recov_sys((rtb_Alarm_flg_n &&
      (bms_Slave_DW.UnitDelay25_DSTATE < 10000.0F) && (bms_Slave_B.Current >=
      bms_Slave_DW.UnitDelay25_DSTATE + 3000.0F)) || ((bms_Slave_B.Current >=
      bms_Slave_DW.UnitDelay25_DSTATE * 1.2 + 1000.0) &&
      (bms_Slave_DW.UnitDelay25_DSTATE >= 10000.0F) && rtb_Alarm_flg_n),
      bms_Slave_B.Current <= bms_Slave_DW.UnitDelay25_DSTATE * 0.95,
      OverCur_DisChrg2_Almtime, OverCur_DisChrg2_Rcvtime,
      &bms_Slave_B.Alarm_flg_gx, &bms_Slave_DW.sf_Alarm_Recov_sys5_l);
    if (bms_Slave_B.Alarm_flg_gx) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch7 = 6U;
      } else {
        rtb_Switch7 = 5U;
      }
    } else {
      rtb_Switch7 = 0U;
    }

    rtb_VectorConcatenate1[3] = (rtb_Switch7 != 0);
    bms_Slave_Alarm_Recov_sys(bms_Slave_B.CellT_max >= CellT_Over_LV2,
      bms_Slave_B.CellT_max < CellT_OverRec_LV2, Cell_OverT2_Almtime,
      Cell_OverT2_Rcvtime, &bms_Slave_B.Alarm_flg_d,
      &bms_Slave_DW.sf_Alarm_Recov_sys9);
    if (bms_Slave_B.Alarm_flg_d) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellT_OverAlert2 = 6U;
      } else {
        rtb_CellT_OverAlert2 = 5U;
      }
    } else {
      rtb_CellT_OverAlert2 = 0U;
    }

    rtb_VectorConcatenate1[4] = ((rtb_CellT_OverAlert1 != 0) ||
      (rtb_CellT_OverAlert2 != 0));
    rtb_VectorConcatenate1[5] = false;
    bms_Slave_Alarm_Recov_sys((rtb_Alarm_flg_n &&
      (bms_Slave_DW.UnitDelay25_DSTATE < 10000.0F) && (bms_Slave_B.Current >=
      bms_Slave_DW.UnitDelay25_DSTATE + 2000.0F)) || ((bms_Slave_B.Current >=
      bms_Slave_DW.UnitDelay25_DSTATE * 1.1 + 1000.0) &&
      (bms_Slave_DW.UnitDelay25_DSTATE >= 10000.0F) && rtb_Alarm_flg_n),
      bms_Slave_B.Current <= bms_Slave_DW.UnitDelay25_DSTATE * 0.95,
      OverCur_DisChrg1_Almtime, OverCur_DisChrg1_Rcvtime,
      &bms_Slave_B.Alarm_flg_jz, &bms_Slave_DW.sf_Alarm_Recov_sys4_i);
    if (bms_Slave_B.Alarm_flg_jz) {
      rtb_Switch5 = 1U;
    } else {
      rtb_Switch5 = 0U;
    }

    rtb_VectorConcatenate1[6] = (rtb_Switch5 != 0);
    bms_Slave_Alarm_Recov_sys(rtb_Alarm_flg_k && (((bms_Slave_B.CellV_min <=
      CellV_Low_LV1_NormalUp) && (bms_Slave_B.CellT_min >= CellV_Low_Temp_Normal))
      || ((bms_Slave_B.CellV_min <= CellV_Low_LV1_TenUp) &&
          (bms_Slave_B.CellT_min < CellV_Low_Temp_Normal) &&
          (bms_Slave_B.CellT_min >= CellV_Low_Temp_Ten)) ||
      ((bms_Slave_B.CellV_min <= CellV_Low_LV1_ZeroUp) && (bms_Slave_B.CellT_min
      >= CellV_Low_Temp_Divid_Zero) && (bms_Slave_B.CellT_min <
      CellV_Low_Temp_Ten)) || ((bms_Slave_B.CellV_min <= CellV_Low_LV1_ZeroBelow)
      && (bms_Slave_B.CellT_min < CellV_Low_Temp_Divid_Zero))),
      ((bms_Slave_B.CellV_min >= CellV_LowRec_LV1_NormalUp) &&
       (bms_Slave_B.CellT_min >= CellV_Low_Temp_Normal)) ||
      ((bms_Slave_B.CellV_min >= CellV_LowRec_LV1_TenUp) &&
       (bms_Slave_B.CellT_min >= CellV_Low_Temp_Ten) && (bms_Slave_B.CellT_min <
      CellV_Low_Temp_Normal)) || ((bms_Slave_B.CellV_min >=
      CellV_LowRec_LV1_ZeroUp) && (bms_Slave_B.CellT_min >=
      CellV_Low_Temp_Divid_Zero) && (bms_Slave_B.CellT_min < CellV_Low_Temp_Ten))
      || ((bms_Slave_B.CellV_min >= CellV_LowRec_LV1_ZeroBelow) &&
          (bms_Slave_B.CellT_min < CellV_Low_Temp_Divid_Zero)),
      Cell_UnderV1_Almtime, Cell_UnderV1_Rcvtime, &bms_Slave_B.Alarm_flg_c3,
      &bms_Slave_DW.sf_Alarm_Recov_sys);
    if (bms_Slave_B.Alarm_flg_c3) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch23 = 1U;
      } else {
        rtb_Switch23 = 5U;
      }
    } else {
      rtb_Switch23 = 0U;
    }

    bms_Slave_Alarm_Recov_sys(rtb_Alarm_flg_k && (((bms_Slave_B.CellV_min <=
      CellV_Low_LV2_NormalUp) && (bms_Slave_B.CellT_min >= CellV_Low_Temp_Normal))
      || ((bms_Slave_B.CellV_min <= CellV_Low_LV2_TenUp) &&
          (bms_Slave_B.CellT_min >= CellV_Low_Temp_Ten) &&
          (bms_Slave_B.CellT_min < CellV_Low_Temp_Normal)) ||
      ((bms_Slave_B.CellV_min <= CellV_Low_LV2_ZeroUp) && (bms_Slave_B.CellT_min
      >= CellV_Low_Temp_Divid_Zero) && (bms_Slave_B.CellT_min <
      CellV_Low_Temp_Ten)) || ((bms_Slave_B.CellV_min <= CellV_Low_LV2_ZeroBelow)
      && (bms_Slave_B.CellT_min < CellV_Low_Temp_Divid_Zero))),
      ((bms_Slave_B.CellV_min >= CellV_LowRec_LV2_NormalUp) &&
       (bms_Slave_B.CellT_min >= CellV_Low_Temp_Normal)) ||
      ((bms_Slave_B.CellV_min >= CellV_LowRec_LV2_TenUp) &&
       (bms_Slave_B.CellT_min >= CellV_Low_Temp_Ten) && (bms_Slave_B.CellT_min <
      CellV_Low_Temp_Normal)) || ((bms_Slave_B.CellV_min >=
      CellV_LowRec_LV2_ZeroUp) && (bms_Slave_B.CellT_min >=
      CellV_Low_Temp_Divid_Zero) && (bms_Slave_B.CellT_min < CellV_Low_Temp_Ten))
      || ((bms_Slave_B.CellV_min >= CellV_LowRec_LV2_ZeroBelow) &&
          (bms_Slave_B.CellT_min < CellV_Low_Temp_Divid_Zero)),
      Cell_UnderV2_Almtime, Cell_UnderV2_Rcvtime, &bms_Slave_B.Alarm_flg_dr,
      &bms_Slave_DW.sf_Alarm_Recov_sys1_j);
    if (bms_Slave_B.Alarm_flg_dr) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch2_d = 5U;
      } else {
        rtb_Switch2_d = 6U;
      }
    } else {
      rtb_Switch2_d = 0U;
    }

    bms_Slave_Alarm_Recov_sys(rtb_Alarm_flg_k && (((bms_Slave_B.CellV_min <=
      CellV_Low_LV3_NormalUp) && (bms_Slave_B.CellT_min >= CellV_Low_Temp_Normal))
      || ((bms_Slave_B.CellV_min <= CellV_Low_LV3_TenUp) &&
          (bms_Slave_B.CellT_min >= CellV_Low_Temp_Ten) &&
          (bms_Slave_B.CellT_min < CellV_Low_Temp_Normal)) ||
      ((bms_Slave_B.CellV_min <= CellV_Low_LV3_ZeroUp) && (bms_Slave_B.CellT_min
      >= CellV_Low_Temp_Divid_Zero) && (bms_Slave_B.CellT_min <
      CellV_Low_Temp_Ten)) || ((bms_Slave_B.CellV_min <= CellV_Low_LV3_ZeroBelow)
      && (bms_Slave_B.CellT_min < CellV_Low_Temp_Divid_Zero))),
      ((bms_Slave_B.CellV_min >= CellV_LowRec_LV3_NormalUp) &&
       (bms_Slave_B.CellT_min >= CellV_Low_Temp_Normal)) ||
      ((bms_Slave_B.CellV_min >= CellV_LowRec_LV3_TenUp) &&
       (bms_Slave_B.CellT_min >= CellV_Low_Temp_Ten) && (bms_Slave_B.CellT_min <
      CellV_Low_Temp_Normal)) || ((bms_Slave_B.CellV_min >=
      CellV_LowRec_LV3_ZeroUp) && (bms_Slave_B.CellT_min >=
      CellV_Low_Temp_Divid_Zero) && (bms_Slave_B.CellT_min < CellV_Low_Temp_Ten))
      || ((bms_Slave_B.CellV_min >= CellV_LowRec_LV3_ZeroBelow) &&
          (bms_Slave_B.CellT_min < CellV_Low_Temp_Divid_Zero)),
      Cell_UnderV3_Almtime, Cell_UnderV3_Rcvtime, &bms_Slave_B.Alarm_flg_jq,
      &bms_Slave_DW.sf_Alarm_Recov_sys19);
    if (bms_Slave_B.Alarm_flg_jq) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellV_LowAlert3 = 5U;
      } else {
        rtb_CellV_LowAlert3 = 7U;
      }
    } else {
      rtb_CellV_LowAlert3 = 0U;
    }

    rtb_VectorConcatenate1[7] = ((rtb_Switch23 != 0) || (rtb_Switch2_d != 0) ||
      (rtb_CellV_LowAlert3 != 0));
    bitIdx = 0;
    rtb_Product = 0U;
    bitMask = 1U;
    for (j = 0; j < 8; j++) {
      if (rtb_VectorConcatenate1[bitIdx]) {
        rtb_Product |= bitMask;
      }

      bitIdx++;
      bitMask <<= 1U;
    }

    bms_Slave_B.CMC_Alarm_2 = (uint8_T)rtb_Product;
    rtb_VectorConcatenate[0] = (bms_Slave_B.CellV_TgtReach != 0);
    rtb_VectorConcatenate[1] = rtb_RelationalOperator6_pt;
    rtb_VectorConcatenate[2] = (bms_Slave_B.Current > 1000);
    if (bms_Slave_B.Current < 0) {
      j = -bms_Slave_B.Current;
    } else {
      j = bms_Slave_B.Current;
    }

    if (j < 0) {
      j = 0;
    }

    rtb_VectorConcatenate[3] = ((uint32_T)j <= 1000U);
    rtb_VectorConcatenate[4] = false;
    rtb_VectorConcatenate[5] = false;
    rtb_VectorConcatenate[6] = false;
    rtb_VectorConcatenate[7] = true;
    bitIdx = 0;
    rtb_Product = 0U;
    bitMask = 1U;
    for (j = 0; j < 8; j++) {
      if (rtb_VectorConcatenate[bitIdx]) {
        rtb_Product |= bitMask;
      }

      bitIdx++;
      bitMask <<= 1U;
    }

    int16_T rtb_Subtract1_ob;
    bms_Slave_B.CMC_Alarm_4 = (uint8_T)rtb_Product;
    bms_Slave_Alarm_Recov_sys(bms_Slave_B.CellT_max >= CellT_Over_LV3,
      bms_Slave_B.CellT_max < CellT_OverRec_LV3, Cell_OverT3_Almtime,
      Cell_OverT3_Rcvtime, &bms_Slave_B.Alarm_flg_ja,
      &bms_Slave_DW.sf_Alarm_Recov_sys10_i);
    rtb_Subtract1_ob = (int16_T)(bms_Slave_B.CellT_max - bms_Slave_B.CellT_min);
    bms_Slave_Alarm_Recov_sys(rtb_Subtract1_ob > CellT_Diff_LV1,
      rtb_Subtract1_ob < CellT_DiffRec_LV1, Cell_TDiff_Almtime,
      Cell_TDiff_Rcvtime, &bms_Slave_B.Alarm_flg_p0,
      &bms_Slave_DW.sf_Alarm_Recov_sys12);
    rtb_Alarm_flg_k = ((bms_Slave_B.AFE_Signal.CellV_Sample_lost_flg != 0) &&
                       bms_Slave_B.LogicalOperator20);
    bms_Slave_Alarm_Recov_sys(rtb_Alarm_flg_k, !rtb_Alarm_flg_k,
      Cell_LostV_Almtime, Cell_LostV_Rcvtime, &bms_Slave_B.Alarm_flg_nt,
      &bms_Slave_DW.sf_Alarm_Recov_sys13);
    bms_Slave_Alarm_Recov_sys(PCB_OverTemp < 0, PCB_OverTempRec >= 0,
      Cell_PCBTover_Almtime, Cell_PCBTover_Rcvtime, &bms_Slave_B.Alarm_flg_c0,
      &bms_Slave_DW.sf_Alarm_Recov_sys18);
    Alarm_nonRecov_sys((bms_Slave_DW.UnitDelay35_DSTATE !=
                        bms_Slave_B.Balance_State) &&
                       bms_Slave_ConstB.LogicalOperator77, Cell_BalCirc_Almtime,
                       &rtb_Alarm_flg_k, &bms_Slave_DW.sf_Alarm_nonRecov_sys);
    if (bms_Slave_B.Alarm_flg_ja) {
      if (rtb_RelationalOperator6_pt) {
        rtb_CellT_OverAlert3 = 7U;
      } else {
        rtb_CellT_OverAlert3 = 6U;
      }
    } else {
      rtb_CellT_OverAlert3 = 0U;
    }

    if (bms_Slave_B.Alarm_flg_p0) {
      rtb_CellTDiff_OverAlert = 1U;
    } else {
      rtb_CellTDiff_OverAlert = 0U;
    }

    if (bms_Slave_B.Alarm_flg_nt) {
      rtb_Switch21 = 7U;
    } else {
      rtb_Switch21 = 0U;
    }

    if (bms_Slave_B.Alarm_flg_c0) {
      rtb_Switch34 = 1U;
    } else {
      rtb_Switch34 = 0U;
    }

    rtb_Alarm_flg_k = (rtb_Switch21 != 0);
    bms_Slave_B.ChrgMOS_Open_Cmd = ((rtb_Switch12_h != 0) ||
      (rtb_CellV_OverAlert2 != 0) || (rtb_CellV_OverAlert3 != 0) ||
      (rtb_CellT_OverAlert3 != 0) || rtb_Alarm_flg_k);
    bms_Slave_B.DisChrgMOS_Open_Cmd = (((bms_Slave_B.Current >= 0) &&
      (rtb_CellV_LowAlert3 != 0)) || rtb_Alarm_flg_k);
    bms_Slave_Alarm_Recov_sys((rtb_Alarm_flg_n &&
      (bms_Slave_DW.UnitDelay25_DSTATE < 10000.0F) && (bms_Slave_B.Current >=
      bms_Slave_DW.UnitDelay25_DSTATE + 4000.0F)) || ((bms_Slave_B.Current >=
      bms_Slave_DW.UnitDelay25_DSTATE * 1.3 + 1000.0) &&
      (bms_Slave_DW.UnitDelay25_DSTATE >= 10000.0F) && rtb_Alarm_flg_n),
      bms_Slave_B.Current <= bms_Slave_DW.UnitDelay25_DSTATE * 0.95,
      OverCur_DisChrg3_Almtime, OverCur_DisChrg3_Rcvtime,
      &bms_Slave_B.Alarm_flg_as, &bms_Slave_DW.sf_Alarm_Recov_sys6);
    if (bms_Slave_B.Alarm_flg_as) {
      rtb_Switch9 = 6U;
    } else {
      rtb_Switch9 = 0U;
    }

    rtb_Alarm_flg_k = ((rtb_Switch9 != 0) || (rtb_CellT_OverAlert3 != 0) ||
                       (rtb_Switch21 != 0));
    bms_Slave_B.ChrgPower_Limit_0 = ((rtb_Switch7 != 0) || (rtb_Switch2_p != 0) ||
      (rtb_Switch12_h != 0) || (rtb_CellV_OverAlert1 != 0) ||
      (rtb_CellV_OverAlert2 != 0) || (rtb_CellV_OverAlert3 != 0) ||
      (rtb_CellT_OverAlert2 != 0) || (rtb_Switch27 != 0) || rtb_Alarm_flg_k);
    bms_Slave_Alarm_Recov_sys(((!rtb_RelationalOperator6_pt) && (0.0F -
      bms_Slave_DW.UnitDelay27_DSTATE >= -10000.0F) && rtb_Alarm_flg_n &&
      (bms_Slave_B.Current <= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) - 4000.0F))
      || ((bms_Slave_B.Current <= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) * 1.3
           - 1000.0) && (0.0F - bms_Slave_DW.UnitDelay27_DSTATE < -10000.0F) &&
          (!rtb_RelationalOperator6_pt) && rtb_Alarm_flg_n), bms_Slave_B.Current
      >= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) * 0.95,
      OverCur_ReChrg3_Almtime, OverCur_ReChrg3_Rcvtime, &bms_Slave_B.Alarm_flg_k,
      &bms_Slave_DW.sf_Alarm_Recov_sys9_m);
    if (bms_Slave_B.Alarm_flg_k) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch15 = 0U;
      } else {
        rtb_Switch15 = 6U;
      }
    } else {
      rtb_Switch15 = 0U;
    }

    bms_Slave_B.DisChrgPower_Limit_0 = ((rtb_Switch15 != 0) || (rtb_Switch2_d !=
      0) || (rtb_CellV_LowAlert3 != 0) || rtb_Alarm_flg_k);
    bms_Slave_B.ChrgPower_Limit_50 = ((rtb_Switch20_p != 0) || (rtb_Switch2_d !=
      0) || (rtb_CellV_LowAlert3 != 0) || (rtb_CellVDiff_OverAlert2 != 0) ||
      (rtb_CellT_OverAlert1 != 0));
    bms_Slave_Alarm_Recov_sys(((!rtb_RelationalOperator6_pt) && (0.0F -
      bms_Slave_DW.UnitDelay27_DSTATE >= -10000.0F) && rtb_Alarm_flg_n &&
      (bms_Slave_B.Current <= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) - 3000.0F))
      || ((bms_Slave_B.Current <= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) * 1.2
           - 1000.0) && (0.0F - bms_Slave_DW.UnitDelay27_DSTATE < -10000.0F) &&
          (!rtb_RelationalOperator6_pt) && rtb_Alarm_flg_n), bms_Slave_B.Current
      >= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) * 0.95,
      OverCur_ReChrg2_Almtime, OverCur_ReChrg2_Rcvtime, &bms_Slave_B.Alarm_flg_g,
      &bms_Slave_DW.sf_Alarm_Recov_sys8_p);
    if (bms_Slave_B.Alarm_flg_g) {
      if (rtb_RelationalOperator6_pt) {
        rtb_Switch13 = 0U;
      } else {
        rtb_Switch13 = 5U;
      }
    } else {
      rtb_Switch13 = 0U;
    }

    bms_Slave_B.DisChrgPower_Limit_50 = ((rtb_Switch7 != 0) || (rtb_Switch13 !=
      0) || (rtb_Switch23 != 0) || (rtb_CellVDiff_OverAlert2 != 0) ||
      (rtb_CellT_OverAlert2 != 0) || (rtb_Switch27 != 0));
    bms_Slave_B.AC_ChrgDisable = ((rtb_Switch12_h != 0) || (rtb_CellV_OverAlert1
      != 0) || (rtb_CellV_OverAlert2 != 0) || (rtb_CellV_OverAlert3 != 0) ||
      (rtb_CellT_OverAlert1 != 0) || (rtb_CellT_OverAlert2 != 0) ||
      (rtb_CellT_OverAlert3 != 0) || (rtb_Switch21 != 0) || (rtb_Switch34 != 0));
    bms_Slave_Alarm_Recov_sys(((!rtb_RelationalOperator6_pt) && (0.0F -
      bms_Slave_DW.UnitDelay27_DSTATE >= -10000.0F) && rtb_Alarm_flg_n &&
      (bms_Slave_B.Current <= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) - 2000.0F))
      || ((bms_Slave_B.Current <= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) * 1.1
           - 1000.0) && (0.0F - bms_Slave_DW.UnitDelay27_DSTATE < -10000.0F) &&
          (!rtb_RelationalOperator6_pt) && rtb_Alarm_flg_n), bms_Slave_B.Current
      >= (0.0F - bms_Slave_DW.UnitDelay27_DSTATE) * 0.95,
      OverCur_ReChrg1_Almtime, OverCur_ReChrg1_Rcvtime, &bms_Slave_B.Alarm_flg_c,
      &bms_Slave_DW.sf_Alarm_Recov_sys7_d);
    if (bms_Slave_B.Alarm_flg_c) {
      rtb_Switch11 = (uint8_T)!rtb_RelationalOperator6_pt;
    } else {
      rtb_Switch11 = 0U;
    }

    tmpForInput[0] = 0U;
    tmpForInput[1] = 0U;
    tmpForInput[2] = 0U;
    tmpForInput[3] = 0U;
    tmpForInput[4] = 0U;
    tmpForInput[5] = 0U;
    tmpForInput[6] = 0U;
    tmpForInput[7] = 0U;
    tmpForInput[8] = 0U;
    tmpForInput[9] = 0U;
    tmpForInput[10] = 0U;
    tmpForInput[11] = 0U;
    tmpForInput[12] = 0U;
    tmpForInput[13] = 0U;
    tmpForInput[14] = 0U;
    tmpForInput[15] = 0U;
    tmpForInput[16] = 0U;
    tmpForInput[17] = rtb_Switch5;
    tmpForInput[18] = rtb_Switch7;
    tmpForInput[19] = rtb_Switch9;
    tmpForInput[20] = rtb_Switch12_h;
    tmpForInput[21] = rtb_Switch2_p;
    tmpForInput[22] = rtb_Switch20_p;
    tmpForInput[23] = rtb_Switch11;
    tmpForInput[24] = rtb_Switch13;
    tmpForInput[25] = rtb_Switch15;
    tmpForInput[26] = rtb_Switch23;
    tmpForInput[27] = rtb_Switch2_d;
    tmpForInput[28] = rtb_CellV_LowAlert3;
    tmpForInput[29] = rtb_CellV_OverAlert1;
    tmpForInput[30] = rtb_CellV_OverAlert2;
    tmpForInput[31] = rtb_CellV_OverAlert3;
    tmpForInput[32] = 0U;
    tmpForInput[33] = 0U;
    tmpForInput[34] = rtb_CellVDiff_OverAlert1;
    tmpForInput[35] = rtb_CellVDiff_OverAlert2;
    tmpForInput[36] = rtb_CellT_OverAlert1;
    tmpForInput[37] = rtb_CellT_OverAlert2;
    tmpForInput[38] = rtb_CellT_OverAlert3;
    tmpForInput[39] = rtb_CellT_LowAlert;
    tmpForInput[40] = rtb_CellTDiff_OverAlert;
    tmpForInput[41] = 0U;
    tmpForInput[42] = rtb_Switch21;
    tmpForInput[43] = rtb_Switch25;
    tmpForInput[44] = rtb_Switch27;
    tmpForInput[45] = 0U;
    tmpForInput[46] = 0U;
    tmpForInput[47] = 0U;
    tmpForInput[48] = 0U;
    tmpForInput[49] = 0U;
    tmpForInput[50] = 0U;
    tmpForInput[51] = 0U;
    tmpForInput[52] = 0U;
    tmpForInput[53] = 0U;
    tmpForInput[54] = 0U;
    tmpForInput[55] = 0U;
    tmpForInput[56] = 0U;
    tmpForInput[57] = 0U;
    tmpForInput[58] = 0U;
    tmpForInput[59] = 0U;
    tmpForInput[60] = 0U;
    tmpForInput[61] = 0U;
    tmpForInput[62] = 0U;
    tmpForInput[63] = 0U;
    tmpForInput[64] = 0U;
    tmpForInput[65] = 0U;
    tmpForInput[66] = 0U;
    tmpForInput[67] = 0U;
    tmpForInput[68] = 0U;
    tmpForInput[69] = 0U;
    tmpForInput[70] = 0U;
    tmpForInput[71] = 0U;
    tmpForInput[72] = 0U;
    tmpForInput[73] = 0U;
    tmpForInput[74] = 0U;
    tmpForInput[75] = 0U;
    tmpForInput[76] = 0U;
    tmpForInput[77] = 0U;
    tmpForInput[78] = rtb_Switch34;
    tmpForInput[79] = 0U;
    bms_Slave_B.Err_Level_n = 0U;
    for (j = 0; j < 79; j++) {
      uint8_T u1;
      u1 = tmpForInput[j + 1];
      if (bms_Slave_B.Err_Level_n < u1) {
        bms_Slave_B.Err_Level_n = u1;
      }
    }

    Alarm_nonRecov_sys(false, Other_OverSOC_Almtime, &rtb_RelationalOperator6_pt,
                       &bms_Slave_DW.sf_Alarm_nonRecov_sys3);
    Alarm_nonRecov_sys(bms_Slave_ConstB.LogicalOperator35 &&
                       (bms_Slave_DW.UnitDelay11_DSTATE -
                        bms_Slave_DW.UnitDelay_DSTATE_l > 10.0F),
                       Other_SOCJump_Almtime, &rtb_RelationalOperator6_pt,
                       &bms_Slave_DW.sf_Alarm_nonRecov_sys5);
    rtb_Add8 = floorf(bms_Slave_DW.UnitDelay8_DSTATE -
                      bms_Slave_DW.UnitDelay10_DSTATE);
    if (rtIsNaNF(rtb_Add8) || rtIsInfF(rtb_Add8)) {
      rtb_Add8 = 0.0F;
    } else {
      rtb_Add8 = fmodf(rtb_Add8, 256.0F);
    }

    Alarm_nonRecov_sys((rtb_Add8 < 0.0F ? (int32_T)(uint8_T)-(int8_T)(uint8_T)
                        -rtb_Add8 : (int32_T)(uint8_T)rtb_Add8) >= 30,
                       Other_CellSOCDiff_Almtime, &rtb_RelationalOperator6_pt,
                       &bms_Slave_DW.sf_Alarm_nonRecov_sys_n);
    Alarm_nonRecov_sys(bms_Slave_ConstB.RelationalOperator1_j,
                       Other_Low1SOH_Almtime, &rtb_RelationalOperator6_pt,
                       &bms_Slave_DW.sf_Alarm_nonRecov_sys1);
    Alarm_nonRecov_sys(bms_Slave_ConstB.RelationalOperator2,
                       Other_Low2SOH_Almtime, &rtb_RelationalOperator6_pt,
                       &bms_Slave_DW.sf_Alarm_nonRecov_sys2);
    Alarm_nonRecov_sys(false, Other_VCURepTmt6_Almtime,
                       &rtb_RelationalOperator6_pt,
                       &bms_Slave_DW.sf_Alarm_nonRecov_sys6);
    Alarm_nonRecov_sys(false, Other_VCURepTmt7_Almtime,
                       &rtb_RelationalOperator6_pt,
                       &bms_Slave_DW.sf_Alarm_nonRecov_sys7);
    rtb_Product = (uint32_T)bms_Slave_B.CellV_mean * CellV_num;
    rtb_RelationalOperator6_pt = (bms_Slave_ConstB.LogicalOperator11 &&
      (ABI_AdcSamplingData.Bat_Vol < 30000U) &&
      bms_Slave_ConstB.LogicalOperator12 && (bms_Slave_B.CellV_min >= 2000) &&
      bms_Slave_ConstB.RelationalOperator8 &&
      bms_Slave_ConstB.RelationalOperator10 && ((uint32_T)-(int32_T)rtb_Product >
      10000U) && (rtb_Product > 200000U));
    bms_Slave_Alarm_Recov_sys(rtb_RelationalOperator6_pt,
      !rtb_RelationalOperator6_pt, Other_SnsrInvalid_Almtime,
      Other_SnsrInvalid_Rcvtime, &rtb_Alarm_flg_n,
      &bms_Slave_DW.sf_Alarm_Recov_sys3_b);
    bms_Slave_B.DTC_ErrCode[0] = 0U;
    bms_Slave_B.DTC_ErrCode[1] = 0U;
    bms_Slave_B.DTC_ErrCode[2] = 0U;
    bms_Slave_B.DTC_ErrCode[3] = 0U;
    bms_Slave_B.DTC_ErrCode[4] = 0U;
    bms_Slave_B.DTC_ErrCode[5] = 0U;
    bms_Slave_B.DTC_ErrCode[6] = 0U;
    bms_Slave_B.DTC_ErrCode[7] = 0U;
    bms_Slave_B.DTC_ErrCode[8] = 0U;
    bms_Slave_B.DTC_ErrCode[9] = 0U;
    bms_Slave_B.DTC_ErrCode[10] = 0U;
    bms_Slave_B.DTC_ErrCode[11] = 0U;
    bms_Slave_B.DTC_ErrCode[12] = 0U;
    bms_Slave_B.DTC_ErrCode[13] = 0U;
    bms_Slave_B.DTC_ErrCode[14] = 0U;
    bms_Slave_B.DTC_ErrCode[15] = 0U;
    bms_Slave_B.DTC_ErrCode[16] = 0U;
    if (rtb_Switch5 != 0) {
      bms_Slave_B.DTC_ErrCode[17] = 18U;
    } else {
      bms_Slave_B.DTC_ErrCode[17] = 0U;
    }

    if (rtb_Switch7 != 0) {
      bms_Slave_B.DTC_ErrCode[18] = 19U;
    } else {
      bms_Slave_B.DTC_ErrCode[18] = 0U;
    }

    if (rtb_Switch9 != 0) {
      bms_Slave_B.DTC_ErrCode[19] = 20U;
    } else {
      bms_Slave_B.DTC_ErrCode[19] = 0U;
    }

    if (rtb_Switch12_h != 0) {
      bms_Slave_B.DTC_ErrCode[20] = 21U;
    } else {
      bms_Slave_B.DTC_ErrCode[20] = 0U;
    }

    if (rtb_Switch2_p != 0) {
      bms_Slave_B.DTC_ErrCode[21] = 22U;
    } else {
      bms_Slave_B.DTC_ErrCode[21] = 0U;
    }

    if (rtb_Switch20_p != 0) {
      bms_Slave_B.DTC_ErrCode[22] = 23U;
    } else {
      bms_Slave_B.DTC_ErrCode[22] = 0U;
    }

    if (rtb_Switch11 != 0) {
      bms_Slave_B.DTC_ErrCode[23] = 24U;
    } else {
      bms_Slave_B.DTC_ErrCode[23] = 0U;
    }

    if (rtb_Switch13 != 0) {
      bms_Slave_B.DTC_ErrCode[24] = 25U;
    } else {
      bms_Slave_B.DTC_ErrCode[24] = 0U;
    }

    if (rtb_Switch15 != 0) {
      bms_Slave_B.DTC_ErrCode[25] = 26U;
    } else {
      bms_Slave_B.DTC_ErrCode[25] = 0U;
    }

    if (rtb_Switch23 != 0) {
      bms_Slave_B.DTC_ErrCode[26] = 27U;
    } else {
      bms_Slave_B.DTC_ErrCode[26] = 0U;
    }

    if (rtb_Switch2_d != 0) {
      bms_Slave_B.DTC_ErrCode[27] = 28U;
    } else {
      bms_Slave_B.DTC_ErrCode[27] = 0U;
    }

    if (rtb_CellV_LowAlert3 != 0) {
      bms_Slave_B.DTC_ErrCode[28] = 29U;
    } else {
      bms_Slave_B.DTC_ErrCode[28] = 0U;
    }

    if (rtb_CellV_OverAlert1 != 0) {
      bms_Slave_B.DTC_ErrCode[29] = 30U;
    } else {
      bms_Slave_B.DTC_ErrCode[29] = 0U;
    }

    if (rtb_CellV_OverAlert2 != 0) {
      bms_Slave_B.DTC_ErrCode[30] = 31U;
    } else {
      bms_Slave_B.DTC_ErrCode[30] = 0U;
    }

    if (rtb_CellV_OverAlert3 != 0) {
      bms_Slave_B.DTC_ErrCode[31] = 32U;
    } else {
      bms_Slave_B.DTC_ErrCode[31] = 0U;
    }

    bms_Slave_B.DTC_ErrCode[32] = 0U;
    bms_Slave_B.DTC_ErrCode[33] = 0U;
    if (rtb_CellVDiff_OverAlert1 != 0) {
      bms_Slave_B.DTC_ErrCode[34] = 35U;
    } else {
      bms_Slave_B.DTC_ErrCode[34] = 0U;
    }

    if (rtb_CellVDiff_OverAlert2 != 0) {
      bms_Slave_B.DTC_ErrCode[35] = 36U;
    } else {
      bms_Slave_B.DTC_ErrCode[35] = 0U;
    }

    if (rtb_CellT_OverAlert1 != 0) {
      bms_Slave_B.DTC_ErrCode[36] = 37U;
    } else {
      bms_Slave_B.DTC_ErrCode[36] = 0U;
    }

    if (rtb_CellT_OverAlert2 != 0) {
      bms_Slave_B.DTC_ErrCode[37] = 38U;
    } else {
      bms_Slave_B.DTC_ErrCode[37] = 0U;
    }

    if (rtb_CellT_OverAlert3 != 0) {
      bms_Slave_B.DTC_ErrCode[38] = 39U;
    } else {
      bms_Slave_B.DTC_ErrCode[38] = 0U;
    }

    if (rtb_CellT_LowAlert != 0) {
      bms_Slave_B.DTC_ErrCode[39] = 40U;
    } else {
      bms_Slave_B.DTC_ErrCode[39] = 0U;
    }

    if (rtb_CellTDiff_OverAlert != 0) {
      bms_Slave_B.DTC_ErrCode[40] = 41U;
    } else {
      bms_Slave_B.DTC_ErrCode[40] = 0U;
    }

    bms_Slave_B.DTC_ErrCode[41] = 0U;
    if (rtb_Switch21 != 0) {
      bms_Slave_B.DTC_ErrCode[42] = 43U;
    } else {
      bms_Slave_B.DTC_ErrCode[42] = 0U;
    }

    if (rtb_Switch25 != 0) {
      bms_Slave_B.DTC_ErrCode[43] = 44U;
    } else {
      bms_Slave_B.DTC_ErrCode[43] = 0U;
    }

    if (rtb_Switch27 != 0) {
      bms_Slave_B.DTC_ErrCode[44] = 45U;
    } else {
      bms_Slave_B.DTC_ErrCode[44] = 0U;
    }

    bms_Slave_B.DTC_ErrCode[45] = 0U;
    bms_Slave_B.DTC_ErrCode[46] = 0U;
    bms_Slave_B.DTC_ErrCode[47] = 0U;
    bms_Slave_B.DTC_ErrCode[48] = 0U;
    bms_Slave_B.DTC_ErrCode[49] = 0U;
    bms_Slave_B.DTC_ErrCode[50] = 0U;
    bms_Slave_B.DTC_ErrCode[51] = 0U;
    bms_Slave_B.DTC_ErrCode[52] = 0U;
    bms_Slave_B.DTC_ErrCode[53] = 0U;
    bms_Slave_B.DTC_ErrCode[54] = 0U;
    bms_Slave_B.DTC_ErrCode[55] = 0U;
    bms_Slave_B.DTC_ErrCode[56] = 0U;
    bms_Slave_B.DTC_ErrCode[57] = 0U;
    bms_Slave_B.DTC_ErrCode[58] = 0U;
    bms_Slave_B.DTC_ErrCode[59] = 0U;
    bms_Slave_B.DTC_ErrCode[60] = 0U;
    bms_Slave_B.DTC_ErrCode[61] = 0U;
    bms_Slave_B.DTC_ErrCode[62] = 0U;
    bms_Slave_B.DTC_ErrCode[63] = 0U;
    bms_Slave_B.DTC_ErrCode[64] = 0U;
    bms_Slave_B.DTC_ErrCode[65] = 0U;
    bms_Slave_B.DTC_ErrCode[66] = 0U;
    bms_Slave_B.DTC_ErrCode[67] = 0U;
    bms_Slave_B.DTC_ErrCode[68] = 0U;
    bms_Slave_B.DTC_ErrCode[69] = 0U;
    bms_Slave_B.DTC_ErrCode[70] = 0U;
    bms_Slave_B.DTC_ErrCode[71] = 0U;
    bms_Slave_B.DTC_ErrCode[72] = 0U;
    bms_Slave_B.DTC_ErrCode[73] = 0U;
    bms_Slave_B.DTC_ErrCode[74] = 0U;
    bms_Slave_B.DTC_ErrCode[75] = 0U;
    bms_Slave_B.DTC_ErrCode[76] = 0U;
    bms_Slave_B.DTC_ErrCode[77] = 0U;
    if (rtb_Switch34 != 0) {
      bms_Slave_B.DTC_ErrCode[78] = 79U;
    } else {
      bms_Slave_B.DTC_ErrCode[78] = 0U;
    }

    bms_Slave_B.DTC_ErrCode[79] = 0U;
    bitIdx = 0;
    rtb_Product = 0U;
    bitMask = 1U;
    for (j = 0; j < 8; j++) {
      if (bms_Slave_ConstB.VectorConcatenate2[bitIdx]) {
        rtb_Product |= bitMask;
      }

      bitIdx++;
      bitMask <<= 1U;
    }

    bms_Slave_B.CMC_Alarm_3 = (uint8_T)rtb_Product;
    bms_Slave_DW.UnitDelay_DSTATE_l = bms_Slave_DW.UnitDelay11_DSTATE;
    bms_Slave_DW.UnitDelay1_DSTATE_f = 0U;
    bms_Slave_DW.UnitDelay2_DSTATE_h = 0U;
  } else if (bms_Slave_DW.Diagnose_system_MODE) {
    bms_Sla_Diagnose_system_Disable();
  }
}
